﻿using System;
using IGolovkine.AoA.BinarySerialization;

namespace IGolovkine.AoA.Tcp
{
    [Serializable]
    public class TcpConnectionInitiated : TcpConnectionMessage
    {
        private readonly string _host;
        private readonly int _port;

        public TcpConnectionInitiated(CorrelationId connectionId, string host, int port)
            : base(connectionId)
        {
            _host = host;
            _port = port;
        }

        protected TcpConnectionInitiated(IBinaryReader reader)
            : base(reader)
        {
            _host = reader.ReadString();
            _port = reader.ReadInt32();
        }

        public string Host
        {
            get { return _host; }
        }

        public int Port
        {
            get { return _port; }
        }

        public override void Serialize(IBinaryWriter writer)
        {
            base.Serialize(writer);
            writer.WriteString(_host);
            writer.WriteInt32(_port);
        }

        public override string ToString()
        {
            return string.Format("{0}: Host = {1}:{2}", this.GetType().Name, _host, _port);
        }
    }
}
